package main;

import main.java.Template;
import org.junit.After;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.util.*;
import java.util.logging.Level;

public class Main {

    static Map<String,String> map =new HashMap();
    public static void main(String args[]){
        Set<String> set = new HashSet<>();
        set.add("bool");
        set.add("char");
        set.add("float");
        set.add("double");
        set.add("void");
        set.add("wchar_t");
        Scanner sc = new Scanner(System.in);
        String typedef,k,v;

        String input="";
        StringBuilder result = new StringBuilder();
        while (sc.hasNext()){
            typedef =sc.next();
            if(sc.hasNext()){
                v =sc.next();
                k = sc.next();
                StringBuilder stringBuilder = new StringBuilder(k);
                stringBuilder.setLength(stringBuilder.length()-1);
                map.put(stringBuilder.toString(),v);
            }else {
                input=typedef;
            }
        }
        if(!map.containsKey(input))
        {
            System.out.println("none");
            return;
        }
        while (map.containsKey(input)){
            StringBuilder temp = new StringBuilder();
            char[] ch =map.get(input).toCharArray();
            for (int i = 0; i < ch.length; i++) {
                if(ch[i]=='*')
                result.append("*");
                else
                    temp.append(ch[i]);
            }
            input =temp.toString();
        }
        if(!set.contains(input)){
            System.out.println("none");
            return;
        }
        if(result.length()!=0)
            result.insert(0," ");
        result.insert(0,input);
        //如果最终的类型不是基本类型，则输出none
        System.out.println(result);
        map.clear();
    }

    public static boolean contain(String input){
        for (String s : map.keySet()) {
            if(s.compareTo(input)==0)
                return true;
        }
        return false;
    }
    @After
    public void after(){

    }
    @Test
    public void test2(){
        String data = "typedef unt INT; typedef INT** INTP;\n" +
                "INTP";
        System.setIn(new ByteArrayInputStream(data.getBytes()));
        String[] args={};
        main(args);
    }
    @Test
    public void test(){
        String data = "typedef int INT; typedef INT** INTP;\n" +
                "";
        System.setIn(new ByteArrayInputStream(data.getBytes()));
        String[] args={};
        main(args);
    }
}


